package service.impl;

import mapper.FlowerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import entity.Flower;
import service.FlowerService;
import utils.Page;

import java.util.List;

@Service("flowerService")
public class FlowerServiceImpl implements FlowerService {
    @Autowired
    private FlowerMapper flowerMapper;
    @Override
    public Page<Flower> getFlowers(Flower flower, Integer pageNo, Integer pageSize) {

        Page<Flower> page = new Page<Flower>();
        page.setPageSize(pageSize);
        // 查询总数，计算总页数
        Integer count = flowerMapper.count(flower);
        page.setTotalCount(count);
        page.setPageNo(pageNo);
        // 查询分页数据
        Integer pageBegin=(pageNo-1)*pageSize;
        List<Flower> data = flowerMapper.getFlowers(flower, page.offset(), page.getPageSize());
        page.setData(data);
        return page;
    }

    @Override
    public boolean insert(Flower flower) {
        return flowerMapper.insert(flower)>0;
    }
}
